﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Frame.Lib.Core.Config;
using Frame.Lib.Core.Register;
using Frame.Lib.Utilities;
using Frame.Lib.Core.Cache;
using Frame.Lib.Core.Cache.SysConfig;

namespace Frame.Web.Admin
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtMac.Text = NetworkAdapter.GetFirstMacAddr();
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            

            try
            {
                //防止非法数据保存进去
                RegisterInfo info = (RegisterInfo)Serialize.BinaryDeserialize(TextBox1.Text);


                SysConfigBO config = new SysConfigBO();
                SysConfigInfo cfgInfo = config.GetInfo(ConfigID.reginfo.ToString());
                bool isAdd = cfgInfo == null;
                cfgInfo = cfgInfo ?? new SysConfigInfo();
                cfgInfo.ID = ConfigID.reginfo.ToString();
                cfgInfo.Config = TextBox1.Text;


                config.Save(cfgInfo, isAdd);

                CacheManager.Instance.Update(typeof(SysConfigLoader));
                JSUtil.Alert("保存成功");

            }
            catch(Exception ex)
            {
                JSUtil.Alert(ex.Message);
            }

            
        }
    }
}
